# _*_ encoding:utf-8 _*_

from __future__ import unicode_literals
from datetime import datetime

from django.db import models

from courses.models import CourseCategory, Course
from users.models import UserProfile

# Create your models here.


class ProjectShow(models.Model):
    """
    项目展示
    """
    coursecategory = models.ForeignKey(CourseCategory, verbose_name="分类")
    name = models.CharField(max_length=36, verbose_name="项目名称")
    user = models.ForeignKey(UserProfile, verbose_name="作者")
    degree_choices = (
        ("cj", "初级"),
        ("zj", "中级"),
        ("gj", "高级")
    )
    degree = models.CharField(verbose_name=u"难度", choices=degree_choices, max_length=2, default="")
    image = models.ImageField(upload_to="project/show/images/%Y/%m" ,max_length=128, verbose_name="项目图片")
    describe = models.CharField(max_length=128, verbose_name="项目描述")
    url = models.URLField(verbose_name="项目讲解链接")
    code = models.FileField(upload_to="project/show/files/%Y/%m", max_length=128, verbose_name="项目源码")
    click_num = models.IntegerField(default=0, verbose_name="点击数")
    students = models.IntegerField(default=0, verbose_name="学习人数")
    course = models.ManyToManyField(Course, verbose_name="相关课程", default="")
    add_time = models.DateTimeField(default=datetime.now, verbose_name=u"添加时间")

    class Meta:
        verbose_name = "项目展示"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name